package demo6;

// 第一个接口 Comparable 接口，实现这个接口表示当前的类是可以进行比较的
class Student implements Comparable<Student> {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student a) {
        if (this.age > a.age) {
            return 1;
        } else if (this.age == a.age) {
            return 0;
        } else {
            return 1;
        }

    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + '}';
    }


}

public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("zhangsan", 10);
        Student student2 = new Student("lisi", 10);
    }
}
